import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:sjx/pages/login/login_page.dart';
import 'package:sjx/pages/login/login_password_page.dart';
import 'package:sjx/pages/login/register_page.dart';
import 'package:sjx/pages/mine/coin/sale_coin_page.dart';
import 'package:sjx/pages/mine/transaction/task_transaction_record_page.dart';
import 'package:sjx/pages/mine/withdrawal/withdrawal_page.dart';
import 'package:sjx/pages/mine/withdrawal/withdrawal_success_page.dart';
import 'package:sjx/pages/setting/about_our_page.dart';
import 'package:sjx/pages/setting/feedback_page.dart';
import 'package:sjx/pages/setting/logoff_page.dart';
import 'package:sjx/pages/setting/person_info_page.dart';
import 'package:sjx/pages/setting/setting_page.dart';
import 'package:sjx/pages/tab_page.dart';
import 'package:sjx/pages/task/create/model/task_step_model.dart';
import 'package:sjx/pages/task/create/step_add/task_create_add_link_page.dart';
import 'package:sjx/pages/task/create/type/task_create_choose_type_page.dart';
import 'package:sjx/pages/task/examine/examine_task_page.dart';
import 'package:sjx/pages/task/pay/task_pay_page.dart';
import 'package:sjx/pages/task/publish/process/task_publish_process_page.dart';
import 'package:sjx/pages/task/publish/task_publish_list_page.dart';
import 'package:sjx/pages/task/receive/task_receive_list_page.dart';
import 'package:sjx/pages/task/submit/detail/task_submit_detail_page.dart';
import 'package:sjx/pages/task/submit/task_submit_vm.dart';
import 'package:sjx/pages/task/success/task_create_success_page.dart';
import 'package:sjx/pages/task/task_detail_page.dart';
import 'package:sjx/repository/model/task_detail_model.dart';

import '../common_ui/web/webview_page.dart';
import '../common_ui/web/webview_widget.dart';
import '../pages/mine/transaction/task_transaction_record_detail_page.dart';
import '../pages/mine/withdrawal/record/task_withdraw_record_page.dart';
import '../pages/setting/band_withdrawal_account_page.dart';
import '../pages/task/create/step_add/task_create_add_copy_page.dart';
import '../pages/task/create/step_add/task_create_add_image_text_page.dart';
import '../pages/task/create/task_create_add_requirement_page.dart';
import '../pages/task/create/task_create_fill_in_page.dart';
import '../pages/task/create/task_create_fill_in_vm.dart';
import '../pages/task/receive/process/task_receive_process_page.dart';
import '../pages/task/submit/task_submit_page.dart';

///路由注册管理类
class Routes {
  static Route<dynamic> generateRoute(RouteSettings settings) {
    switch (settings.name) {
      case RoutePath.tab:
        return pageRoute(const TabPage(), settings: settings);
      case RoutePath.task_detail:
        return pageRoute(
          TaskDetailPage(taskId: settings.arguments as String),
          settings: settings,
        );
      case RoutePath.task_submit:
        final args = settings.arguments as Map<String, dynamic>? ?? {};
        return pageRoute(
          TaskSubmitPage(
            taskNo: args['taskNo']
          ),
          settings: settings,
        );
      case RoutePath.task_submit_detail:
        final args = settings.arguments as Map<String, dynamic>? ?? {};
        return pageRoute(
          TaskSubmitDetailPage(
            taskNo: args['taskNo'],
            orderNo: args['orderNo'],
          ),
          settings: settings,
        );
      case RoutePath.task_receive_process:
        final args = settings.arguments as Map<String, dynamic>? ?? {};
        return pageRoute(
          ReceiveTaskProcessPage(
              orderNo: args['orderNo']
          ),
          settings: settings,
        );
      case RoutePath.task_receive_list:
        final args = settings.arguments as Map<String, dynamic>? ?? {};
        return pageRoute(ReceiveTaskPage(
          taskStatusNumberModel: args['taskStatusNumber'],
          initialIndex: args['index'],
        ), settings: settings);
      case RoutePath.task_publish_list:
        final args = settings.arguments as Map<String, dynamic>? ?? {};
        return pageRoute(PublishTaskPage(
          taskStatusNumberModel: args['taskStatusNumber'],
          initialIndex: args['index'],
        ), settings: settings);
      case RoutePath.task_create_choose_type:
        final args = settings.arguments as Map<String, dynamic>? ?? {};
        return pageRoute(TaskCreateChooseTypePage(
          taskCategoryStr: args['taskCategoryStr'],
            refreshHandle: args['refreshHandle']
        ), settings: settings);
      case RoutePath.task_create_fill_in:
        final args = settings.arguments as Map<String, dynamic>? ?? {};
        return pageRoute(TaskCreateFillInPage(
            taskCategoryStr: args['taskCategoryStr'],
            serviceFeePercent: args['serviceFeePercent'],
            taskId: args['taskId'],
            againCreate: args['againCreate'],
        ), settings: settings);
      case RoutePath.task_create_add_image_text:
        final args = settings.arguments;
        return pageRoute(TaskCreateAddImageTextPage(object: args is TaskStepModel ? args : null), settings: settings);
      case RoutePath.task_create_add_link:
        final args = settings.arguments;
        return pageRoute(TaskCreateAddLinkPage(object: args is TaskStepModel ? args : null), settings: settings);
      case RoutePath.task_create_add_copy:
        final args = settings.arguments;
        return pageRoute(TaskCreateAddCopyPage(object: args is TaskStepModel ? args : null), settings: settings);
      case RoutePath.task_create_add_requirement:
        final args = settings.arguments;
        return pageRoute(TaskCreateAddRequirementPage(object: args is TaskCreateFillInViewModel ? args : null), settings: settings);
      case RoutePath.login:
        return pageRoute(const LoginPage(), settings: settings);
      case RoutePath.login_password:
        return pageRoute(const LoginPasswordPage(), settings: settings);
      case RoutePath.setting:
        return pageRoute(const SettingPage(), settings: settings);
      case RoutePath.register:
        return pageRoute(const RegisterPage(), settings: settings);
      case RoutePath.web_view:
        final args = settings.arguments as Map<String, dynamic>? ?? {};
        return pageRoute(
          WebViewPage(
            loadResource: args['url'] ?? "",
            webViewType: WebViewType.URL,
          ),
          settings: settings,
        );
      case RoutePath.task_create_success:
        final args = settings.arguments as Map<String, dynamic>? ?? {};
        return pageRoute(TaskCreateSuccessPage(taskId: args['taskId'], taskCategoryStr: args['taskCategoryStr']), settings: settings);
      case RoutePath.task_pay:
        final args = settings.arguments as Map<String, dynamic>? ?? {};
        return pageRoute(TaskPayPage(
          taskId: args['taskId'],
          amountStr: args['amountStr'],
          refreshHandle: args['refreshHandle'] ?? (),
          isAddTask: args['isAddTask'] ?? false,
        ), settings: settings);
      case RoutePath.task_publish_examine:
        final args = settings.arguments as Map<String, dynamic>? ?? {};
        return pageRoute(ExamineTaskPage(taskNo: args['taskId']), settings: settings);
      case RoutePath.task_publish_process:
        final args = settings.arguments as Map<String, dynamic>? ?? {};
        return pageRoute(
          PublishTaskProcessPage(
              taskNo: args['taskNo']
          ),
          settings: settings,
        );
      case RoutePath.about_our:
        return pageRoute(const AboutOurPage(), settings: settings);
      case RoutePath.feedback:
        return pageRoute(const FeedbackPage(), settings: settings);
      case RoutePath.logoff:
        return pageRoute(const LogOffPage(), settings: settings);
      case RoutePath.person_info:
        return pageRoute(const PersonInfoPage(), settings: settings);
      case RoutePath.band_withdraw_account:
        return pageRoute(const BandWithdrawalAccountPage(), settings: settings);
      case RoutePath.withdrawal:
        return pageRoute(const WithdrawalPage(), settings: settings);
      case RoutePath.withdrawal_success:
        return pageRoute(const WithdrawalSuccessPage(), settings: settings);
      case RoutePath.withdrawal_record:
        return pageRoute(const TaskWithdrawRecordPage(), settings: settings);
      case RoutePath.transaction_record_cash:
        return pageRoute(const TaskTransactionRecordDetailPage(type: TaskRecordType.cash), settings: settings);
      case RoutePath.transaction_record_coin:
        return pageRoute(const TaskTransactionRecordDetailPage(type: TaskRecordType.coin), settings: settings);
      case RoutePath.sale_coin:
        return pageRoute(const SaleCoinPage(), settings: settings);

    }
    return MaterialPageRoute(
      builder: (context) => Scaffold(
        body: Center(child: Text('No route defined for ${settings.name}')),
      ),
    );
  }

  static MaterialPageRoute pageRoute(
    Widget page, {
    RouteSettings? settings,
    bool? fullscreenDialog,
    bool? maintainState,
    bool? allowSnapshotting,
  }) {
    return MaterialPageRoute(
      builder: (context) => page,
      settings: settings,
      fullscreenDialog: fullscreenDialog ?? false,
      maintainState: maintainState ?? true,
      allowSnapshotting: allowSnapshotting ?? true,
    );
  }
}

///路由地址
class RoutePath {
  //首页tab
  static const String tab = "/";
  //任务详情页
  static const String task_detail = "/task_detail";
  //登录页
  static const String login = "/login";
  //显示网页资源的页面
  static const String web_view = "/web_view";
  //密码登录页
  static const String login_password = "/login_password";
  //设置页
  static const String setting = "/setting";
  //注册页
  static const String register = "/register";
  //提交任务页面
  static const String task_submit = "/task_submit";
  //发布任务列表
  static const String task_publish_list = "/task_publish_list";
  //正在做任务列表
  static const String task_receive_list = "/task_receive_list";
  //正在做任务进程
  static const String task_receive_process = "/task_receive_process";
  //提交任务内容页面
  static const String task_submit_detail = "/task_submit_detail";
  //创建任务类型选择页面
  static const String task_create_choose_type = "/task_create_choose_type";
  //创建任务类型页面
  static const String task_create_fill_in = "/task_create_fill_in";
  //创建任务类型-图文
  static const String task_create_add_image_text = "/task_create_add_image_text";
  //创建任务类型-网址
  static const String task_create_add_link = "/task_create_add_link";
  //创建任务类型-复制
  static const String task_create_add_copy = "/task_create_add_copy";
  //创建任务类型-任务要求
  static const String task_create_add_requirement = "/task_create_add_requirement";
  //发布任务成功页面
  static const String task_create_success = "/task_create_success";
  //支付页面
  static const String task_pay = "/task_pay";
  //发布者任务审核页面
  static const String task_publish_examine = "/task_publish_examine";
  //发布者任务进程页面
  static const String task_publish_process = "/task_publish_process";
  //关于我们
  static const String about_our = "/about_our";
  //意见反馈
  static const String feedback = "/feedback";
  //注销账户
  static const String logoff = "/logoff";
  //个人资料
  static const String person_info = "/person_info";
  //提现账户
  static const String band_withdraw_account = "/band_withdraw_account";
  //提现页面
  static const String withdrawal = "/withdrawal";
  //提现成功页面
  static const String withdrawal_success = "/withdrawal_success";
  //提现记录
  static const String withdrawal_record = "/withdrawal_record";
  //现金明细流水
  static const String transaction_record_cash = "/transaction_record_cash";
  //金币明细流水
  static const String transaction_record_coin = "/transaction_record_coin";
  //出售金币
  static const String sale_coin = "/sale_coin";

}
